package edu.gatech.oad.mule;

import java.awt.Rectangle;

import edu.gatech.oad.mule.model.GameStateMachine.GameState;
import edu.gatech.oad.mule.view.interfaces.RenderableBuilding;

/**
 * This class represents a MULE outfitter in the town.  Here, a Player can 
 * equip the MULE with technology to harvest a particular type of resource on 
 * a plot of land.
 *
 * @author Brendan McGarry, Dale Avery, D'Miria Collins, Natasha Parekh, Jaemin Park
 * @version %I%, %G%
 */
public class Outfitter extends Zone implements RenderableBuilding{

	//what type of outfitter this is (based off
	//  of the MULE types)
	private char type;

	//cost to use this outfitter
	private int cost;

	//prices to outfit each type of MULE
	private static int foodCost = 25;
	private static int energyCost = 50;
	private static int smithoreCost = 75;
	private static int crystiteCost = 100;

	/**
	 * Creates a new Outfitter.  Passes everything to
	 * the zone class
	 *
	 * @param x The x coordinate of the Outfitter
	 * @param y The y coordinate of the Outfitter
	 * @param width The width of the Outfitter
	 * @param height The height of the Outfitter
	 */
	public Outfitter(int x, int y, int width, int height, char type){
		//call up to the zone
		super(x, y, width, height);
		//set the type
		this.type = type;
		//calculate the cost of using this shop
		if(type == MULE.FOOD){
			cost = foodCost;
		}//end if
		else if(type == MULE.ENERGY){
			cost = energyCost;
		}//end else if
		else if(type == MULE.SMITHORE){
			cost = smithoreCost;
		}//end else if
		else if(type == MULE.CRYSTITE){
			cost = crystiteCost;
		}//end else if
	}//end constructor

	@Override
	public void interact(Player p, GameState phase, int round, int time){
		System.out.print(p.getName() + " enters the MULE outfitter with [" + p.getMoney() + "]. ");
		//player has sufficient funds to outfit this MULE
		if(p.getMoney() >= cost){
			//player has a MULE to outfit
			if(p.getMULE() != null){
				//player doesn't have an outfitted MULE
				if(!p.hasOutfittedMULE()){
					//outfit the MULE
					p.getMULE().outfit(type);
					//subtract the funds
					p.addMoney(-1 * cost);
					System.out.print(p.getName() + " spent [" + cost + "] to outfit MULE. ");
				}//end if
				else{
					System.out.print(p.getName() + " cannot reoutfit MULE.");
				}//end else
			}//end if
			else{
				System.out.print(p.getName() + " has no MULE in inventory to outfit. ");
			}//end else
		}//end if
		else{
			System.out.print(p.getName() + " insufficient funds. ");
		}//end else
		System.out.println(p.getName() + " leaves with a balance of [" + p.getMoney() + "]");
	}//end method interact
	
	//====================
	//	RenderableBuilding
	//====================
	
	@Override
	public BuildingType getBuildingType(){
		if(type == MULE.ENERGY){
			return BuildingType.OUTFITTER_ENERGY;
		}//end if
		else if(type == MULE.FOOD){
			return BuildingType.OUTFITTER_FOOD;
		}//end else if
		else if(type == MULE.SMITHORE){
			return BuildingType.OUTFITTER_ORE;
		}//end else if
		else if(type == MULE.CRYSTITE){
			return BuildingType.OUTFITTER_CRYSTITE;
		}//end else if
		return BuildingType.ERROR;
	}//end method getBuildingType
	
	@Override
	public int getCost(){
		return cost;
	}//end method getCost

}//end class Outfitter

